package com.wushijia.sort;

import java.util.Arrays;

/**
 * 冒泡排序
 *
 * @author Administrator
 * @date 2021-06-15 10:14
 */
public class BubbleSort {

  public static void main(String[] args) {
    int[] arr = {4, 1, 6, 9, 10, 22, 1, 7, 8, 100};

    int length = arr.length;
    for (int i = 0; i < length; i++) {
      for (int j = 0; j < length - i - 1; j++) {
        int temp1 = arr[j];
        int temp2 = arr[j + 1];

        if (temp1 > temp2) {
          swap(arr, j, j + 1);
        }
        System.out.println(Arrays.toString(arr));
      }
    }

  }

  private static void swap(int[] arr, int i, int j) {
    int temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }

}
